package com.zhijiaoyun.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.zhijiaoyun.common.DsConstant;
import com.zhijiaoyun.common.ResponseUtils;
import org.springframework.stereotype.Service;

import com.zhijiaoyun.dao.IMarkDao;
import com.zhijiaoyun.model.Mark;
import com.zhijiaoyun.service.IMarkService;

/**
 * @author shisfish
 * @date 2017/6/6
 */
@Service(value = "markService")
public class MarkServiceImpl implements IMarkService {

	@Resource
	IMarkDao markDao;
	
	@Override
	public List<Mark> getByParams(String name) {
		return markDao.selectByParams(name);
	}

	@Override
	public Mark getMarkByMarkId(Long markId) {
		return markDao.selectByPrimaryKey(markId);
	}

	@Override
	public void modifyMark(Mark mark) {
		markDao.updateByPrimaryKey(mark);
	}

	@Override
	public Mark getMarkByNameNotMarkId(Long markId, String name) {
		return markDao.selectByNameNotMarkId(markId, name);
	}

	@Override
	public Map<String, Object> addMark(Mark mark) {
		Mark objMark = getMarkByName(mark.getName());
		if (objMark != null) {
			return ResponseUtils.responseErrorMap(DsConstant.CODE_ADD_SHOPPING_CART_ORDER_ERROR, "标签已存在");
		}
		markDao.insert(mark);
		return ResponseUtils.responseSuccessMap();
	}

	@Override
	public Mark getMarkByName(String name) {
		return null;
	}

	@Override
	public void deleteMark(Mark mark) {
		markDao.deleteByPrimaryKey(mark.getId());
	}

}
